from django.http import HttpResponseRedirect
from django.forms import ModelForm
from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from atschool.apps.littlething.models import Thing

class ThingForm(ModelForm):
    class Meta:
        model = Thing 
        exclude = ['author','status']

@login_required
def create_entry(request):
    if request.method == 'POST':
        form = ThingForm(data=request.POST)
        if form.is_valid():
            new_entry = form.save(commit=False)
            new_entry.author = request.user
            new_entry.status = 1
            new_entry.save()
            return HttpResponseRedirect(new_entry.get_absolute_url())
    else:
        form = ThingForm()
    return render_to_response('littlething/create_thing.html',
                              { 'form': form })

